package com.zhiyou.app.shop.website.action;

import org.apache.struts2.ServletActionContext;

import com.zhiyou.app.shop.common.BaseAction;

import java.io.FileInputStream;
import java.io.InputStream;

public class DownLoadTempletAction extends BaseAction {
	
	private static final long serialVersionUID = 1L;
	private String inputPath;
	private String downloadFileName;
	private boolean _isExternal = false;
	
    /*@Autowired
    private IEpmsattachmentService epmsattachmentService;*/

	public void setDownloadFileName(String downloadFileName) {
		this.downloadFileName = downloadFileName;
	}

	public String getDownloadFileName() {
		
		return downloadFileName;
	}

	public void setInputPath(String value) {
		inputPath = value;
	}

	public void set_isExternal(boolean _isExternal) {
		this._isExternal = _isExternal;
	}

	@SuppressWarnings("resource")
	public InputStream getTargetFile() throws Exception {
		InputStream in = null;
		if(_isExternal){
			in = new FileInputStream(inputPath);
		}else{
			in = ServletActionContext.getServletContext()
				.getResourceAsStream(inputPath);
		}
		return in;
	}

	public String download() throws Exception {
		return SUCCESS;
	}
}
